<template>
  <div class="app-container">
    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="等级" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.level }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="等级昵称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="可开设集合室" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.count }}</span>
        </template>
      </el-table-column>
      <el-table-column label="集合室售价" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="scope">
          <div>
            <span v-permission="['/library/answerEdit']">
              <el-button size="small" type="primary" @click="edit(scope.row)">编 辑</el-button>
            </span>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="编辑角色" :visible.sync="show">
      <el-form>
        <el-form-item label="等级名称" label-width="150px">
          <el-input v-model="item.name" />
        </el-form-item>
        <el-form-item label="可开设集合室" label-width="150px">
          <el-input v-model="item.count" />
        </el-form-item>
        <el-form-item label="集合室售价" label-width="150px">
          <el-input v-model="item.money" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handle()">确 定</el-button>
      </div>
      <!-- <el-alert title="售价如果设置为0则认为不是高分答案" type="info" center show-icon></el-alert> -->
    </el-dialog>
  </div>
</template>

<script>
  import {
    roleList,
    roleEdit
  } from '@/api/interview';
  import {
    addressList
  } from '@/api/config';
  import waves from '@/directive/waves';
  import Pagination from '@/components/Pagination';
  import permission from '@/directive/permission/index.js';
  import {
    dateHandle
  } from '@/api/dateHandle';
  import imageUpload from '@/components/Upload/image';

  export default {
    components: {
      Pagination,
      imageUpload
    },
    directives: {
      waves,
      permission,

    },
    data() {
      return {
        tableKey: 0,
        list: null,
        listLoading: false,
        show: false,
        item: {}
      };
    },
    created() {
      this.getList()
    },
    methods: {
      _date(t) {
        return dateHandle('Y-m-d H:i:s', t)
      },
      handle() {
        roleEdit(this.item).then(res => {
          console.log(res);
          if (res.code == 20000) {
            this.$message({
              type: 'success',
              message: res.msg
            });
            this.show = false;
            this.getList()
          }
        })
      },
      edit(item) {
        this.show = true
        this.item = item
      },
      getList() {
        this.listLoading = true;
        roleList(this.listQuery).then(res => {
          this.list = res.data
          setTimeout(() => {
            this.listLoading = false;
          }, 0.3 * 1000);
        });
      },

    }
  };
</script>
